package com.shixu.framework.plugins.sms;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import com.shixu.framework.core.AppContext;
import com.shixu.framework.plugins.sms.utils.HttpKit;
import com.shixu.framework.util.MD5;
import com.shixu.framework.util.StringUtils;

public class SmsSender {
	
	private static String SMS_URL = AppContext.getInstance().getString("sms.url");
	
	private static String SMS_USER = AppContext.getInstance().getString("sms.user");
	
	private static String SMS_PWD = AppContext.getInstance().getString("sms.pwd");
	
	
	public static String sendSms(String tel ,String txt) throws IOException, ExecutionException, InterruptedException{
		Map<String,String> params = new HashMap<String,String>(); 
		params.put("uid", SMS_USER);
		params.put("pwd", MD5.toMD5(SMS_PWD+SMS_USER));
		params.put("encode", "utf8");
		params.put("mobile", tel);
		params.put("content", txt);
		
		
		return HttpKit.post(SMS_URL, params);
	}
	

	
	public static String sendSms(String[] tel ,String txt) throws IOException, ExecutionException, InterruptedException{
		Map<String,String> params = new HashMap<String,String>(); 
		params.put("uid", SMS_USER);
		params.put("pwd", MD5.toMD5(SMS_PWD+SMS_USER));
		params.put("encode", "utf8");
		params.put("mobile", StringUtils.join(tel, ","));
		params.put("content", txt);
		
		
		return HttpKit.post(SMS_URL, params);
	}
	
}